package com.venue.hjt.venueclass.db;


import android.util.Log;

import com.venue.hjt.venueclass.BaseApplication;

import java.util.List;

/**
 * Created by xqx on 2017/10/27.
 * 数据库操作
 */

public class CardDao {

    /**
     * @param shop
     * 添加卡号
     */
    public static void insertCard(Cardnumber shop) {
        BaseApplication.getDaoInstant().getCardnumberDao().insertOrReplace(shop);
    }
    public static void insertEvaluate(VenueEvaluate shop) {
        BaseApplication.getDaoInstant().getVenueEvaluateDao().insertOrReplace(shop);
    }
    public static void insertVenueSign(VenueSign shop) {
        BaseApplication.getDaoInstant().getVenueSignDao().insertOrReplace(shop);
    }
    public static void insertVenueBooKing(VenueBooKing shop) {
        BaseApplication.getDaoInstant().getVenueBooKingDao().insertOrReplace(shop);
    }
    public static void insertKeyword(VenueKeyword shop) {
        BaseApplication.getDaoInstant().getVenueKeywordDao().insertOrReplace(shop);
    }
    public static void insertInfo(VenueInfo shop) {
        BaseApplication.getDaoInstant().getVenueInfoDao().insertOrReplace(shop);
    }
    public static void insertHour(VenueHour shop) {
        BaseApplication.getDaoInstant().getVenueHourDao().insertOrReplace(shop);
    }
    public static void insertGroup(VenueGroup shop) {
        BaseApplication.getDaoInstant().getVenueGroupDao().insertOrReplace(shop);
    }
    /**
     * @param shop
     * 添加
     */
    public static void insertDynamicSchool(DynamicSchool shop) {
        BaseApplication.getDaoInstant().getDynamicSchoolDao().insertOrReplace(shop);
    }

    public static List<DynamicSchool> queryDynamicSchoolId(String id) {
        return BaseApplication.getDaoInstant().getDynamicSchoolDao().queryBuilder().where(DynamicSchoolDao.Properties.Id.eq(id)).list();
    }
    public static List<DynamicSchool> queryDynamicSchool() {
        return BaseApplication.getDaoInstant().getDynamicSchoolDao().queryBuilder().list();
    }

    /**
     * @param id
     * @return 返回搜到的id的卡号数据
     * 查询卡号id
     */
    public static List<Cardnumber> queryLove(String id) {
        return BaseApplication.getDaoInstant().getCardnumberDao().queryBuilder().where(CardnumberDao.Properties.Cardnumber.eq(id)).list();
    }
    public static List<Cardnumber> queryLoveID(String id) {
        return BaseApplication.getDaoInstant().getCardnumberDao().queryBuilder().where(CardnumberDao.Properties.Id.eq(id)).list();
    }

    /**
     * @param student_card
     * 添加学生
     */
    public static void insertStuden(CardStudent student_card){
        BaseApplication.getDaoInstant().getCardStudentDao().insertOrReplace(student_card);
    }

    /**
     * @return 返回学生数据
     */
    public static List<CardStudent> queryStudent() {
        return BaseApplication.getDaoInstant().getCardStudentDao().queryBuilder().list();
    }
    /**
     * @param id
     * @return 返回指定id的学生数据
     */
    public static List<CardStudent> queryStudentId(String id) {
        return BaseApplication.getDaoInstant().getCardStudentDao().queryBuilder().where(CardStudentDao.Properties.Id.eq(id)).list();
    }
    public static List<VenueHour> queryHourId(String id) {
        return BaseApplication.getDaoInstant().getVenueHourDao().queryBuilder().where(VenueHourDao.Properties.Id.eq(id)).list();
    }
    public static List<VenueHour> queryHourS(String id,String week) {
        return BaseApplication.getDaoInstant().getVenueHourDao().queryBuilder().where(VenueHourDao.Properties.Status.eq(id)).orderAsc(VenueHourDao.Properties.Start_time).where(VenueHourDao.Properties.Weekday.eq(week)).list();
    }
    public static List<VenueInfo> queryInfo(String id) {
        return BaseApplication.getDaoInstant().getVenueInfoDao().queryBuilder().where(VenueInfoDao.Properties.Id.eq(id)).list();
    }
    public static List<VenueInfo> queryInfo() {
        return BaseApplication.getDaoInstant().getVenueInfoDao().queryBuilder().list();
    }
    public static List<VenueSign> queryVenueSignType(int type) {
        return BaseApplication.getDaoInstant().getVenueSignDao().queryBuilder().where(VenueSignDao.Properties.Sign_type.eq(type)).list();
    }
    public static List<VenueBooKing> queryVenueBooKingId(String id) {
        return BaseApplication.getDaoInstant().getVenueBooKingDao().queryBuilder().where(VenueBooKingDao.Properties.Id.eq(id)).list();
    }
    public static List<VenueBooKing> queryVenueBooKing() {
        return BaseApplication.getDaoInstant().getVenueBooKingDao().queryBuilder().orderDesc(VenueBooKingDao.Properties.Start_time).list();
    }
    public static List<VenueEvaluate> queryEvaluate (String id,int type) {
        return BaseApplication.getDaoInstant().getVenueEvaluateDao().queryBuilder().where(VenueEvaluateDao.Properties.Id.eq(id)).where(VenueEvaluateDao.Properties.Type.eq(type)).list();
    }
    public static List<VenueKeyword> queryKey(String id,int type) {
        return BaseApplication.getDaoInstant().getVenueKeywordDao().queryBuilder().where(VenueKeywordDao.Properties.Id.eq(id)).where(VenueKeywordDao.Properties.Type.eq(type)).list();
    }
    public static List<VenueKeyword> queryKey() {
        return BaseApplication.getDaoInstant().getVenueKeywordDao().queryBuilder().list();
    }
    public static void updateStudent(CardStudent shop) {
        BaseApplication.getDaoInstant().getCardStudentDao().update(shop);
    }
    public static void updateVenueGroupType(VenueGroup venueSign) {
        Log.e("ATG"," 更新成功");
       BaseApplication.getDaoInstant().getVenueGroupDao().update(venueSign);
    }
    public static void updateVenueSignType(VenueSign venueSign) {
        Log.e("ATG"," 更新成功");
        BaseApplication.getDaoInstant().getVenueSignDao().update(venueSign);
    }
    /**
     * @param id
     * @return 返回指定id的数据
     */
    public static List<SchArticle> querySchArticle(String id) {
        return BaseApplication.getDaoInstant().getSchArticleDao().queryBuilder().where(SchArticleDao.Properties.Id.eq(id)).list();
    }
    /**
     * @param id
     * @return 返回指定id的数据
     */
    public static List<SchAboutUs> querySchAboutUs(String id) {
        return BaseApplication.getDaoInstant().getSchAboutUsDao().queryBuilder().where(SchAboutUsDao.Properties.Id.eq(id)).list();
    }
    public static List<VenueEvaluate> queryVenueEvaluateType(String id) {
        return BaseApplication.getDaoInstant().getVenueEvaluateDao().queryBuilder().where(VenueEvaluateDao.Properties.Type.eq(id)).list();
    }
    public static List<VenueEvaluate> queryVenueEvaluate() {
        return BaseApplication.getDaoInstant().getVenueEvaluateDao().queryBuilder().list();
    }
    /**
     * @param shop
     * 添加轮播图和班级荣誉相册
     */
    public static void insertAlbum(SchAlbum shop) {
        BaseApplication.getDaoInstant().getSchAlbumDao().insertOrReplace(shop);
    }
    public static void updateEvaluate(VenueEvaluate shop) {
        Log.e("ATG","更新");
        BaseApplication.getDaoInstant().getVenueEvaluateDao().update(shop);
    }
    /**
     * @param id
     * @return 返回指定id的数据
     */
    public static List<SchAlbum> queryAlbumId(String id) {
        return BaseApplication.getDaoInstant().getSchAlbumDao().queryBuilder().where(SchAlbumDao.Properties.Id.eq(id)).list();
    }
    public static List<VenueKeyword> queryComplaint(String id) {
        return BaseApplication.getDaoInstant().getVenueKeywordDao().queryBuilder().where(VenueKeywordDao.Properties.Type.eq(id)).list();
    }
    /**
     * @param id
     * @return 返回指定id的数据
     */
    public static List<SchAlbum> queryAlbumType(String id) {
        return BaseApplication.getDaoInstant().getSchAlbumDao().queryBuilder().where(SchAlbumDao.Properties.Typeid.eq(id)).list();
    }
    /**
     * @return 返回轮播图和荣誉相册图片
     */
    public static List<SchAlbum> queryAlbum() {
        return BaseApplication.getDaoInstant().getSchAlbumDao().queryBuilder().list();
    }
    public static List<VenueInfo> queryVenueInfo() {
        return BaseApplication.getDaoInstant().getVenueInfoDao().queryBuilder().list();
    }


    /**
     * @param schArticle
     * 添加信息
     */
    public static void insertAchArticle(SchArticle schArticle){
        BaseApplication.getDaoInstant().getSchArticleDao().insertOrReplace(schArticle);
    }
    /**
     * @param schAboutUs
     * 添加信息
     */
    public static void insertSchAboutUs(SchAboutUs schAboutUs){
        BaseApplication.getDaoInstant().getSchAboutUsDao().insertOrReplace(schAboutUs);
    }

    /**
     * @return 返回数据
     */
    public static List<SchArticle> querySchArticle() {
        return BaseApplication.getDaoInstant().getSchArticleDao().queryBuilder().orderDesc(SchArticleDao.Properties.Sort).list();
    }
    /**
     * @return 返回数据
     */
    public static List<SchArticle> querySchArticleId(String id) {
        return BaseApplication.getDaoInstant().getSchArticleDao().queryBuilder().where(SchArticleDao.Properties.Id.eq(id)).list();
    }
    /**
     * @return 返回数据
     */
    public static List<SchAboutUs> querySchAboutUs() {
        return BaseApplication.getDaoInstant().getSchAboutUsDao().queryBuilder().orderDesc(SchAboutUsDao.Properties.Sort).list();
    }
    public static List<VenueGroup> queryVenueGroup() {
        return BaseApplication.getDaoInstant().getVenueGroupDao().queryBuilder().list();
    }

    public static List<VenueGroup> queryGroupId(String id) {
        return BaseApplication.getDaoInstant().getVenueGroupDao().queryBuilder().where(VenueGroupDao.Properties.Id.eq(id)).list();
    }
    public static List<VenueGroup> queryVenueGroupId(String id,String sign) {
        return BaseApplication.getDaoInstant().getVenueGroupDao().queryBuilder().where(VenueGroupDao.Properties.G_id.eq(id)).where(VenueGroupDao.Properties.Sign.eq(sign)).list();
    }
    public static List<VenueHour> queryHourWeek(String id) {
        return BaseApplication.getDaoInstant().getVenueHourDao().queryBuilder().where(VenueHourDao.Properties.Weekday.eq(id)).orderAsc(VenueHourDao.Properties.Start_time).list();
    }
    /**
     * 删除
     */
    public static void deleteAll(){
        BaseApplication.getDaoInstant().getCardStudentDao().deleteAll();
        BaseApplication.getDaoInstant().getCardnumberDao().deleteAll();
        BaseApplication.getDaoInstant().getDynamicSchoolDao().deleteAll();
        BaseApplication.getDaoInstant().getVenueHourDao().deleteAll();
        BaseApplication.getDaoInstant().getVenueEvaluateDao().deleteAll();
        BaseApplication.getDaoInstant().getVenueInfoDao().deleteAll();
        BaseApplication.getDaoInstant().getVenueKeywordDao().deleteAll();
        BaseApplication.getDaoInstant().getVenueGroupDao().deleteAll();
        BaseApplication.getDaoInstant().getVenueBooKingDao().deleteAll();
        BaseApplication.getDaoInstant().clear();
    }
}
